package com.hs.telepass.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import com.hs.teleform.R;
import com.hs.telepass.MainApp;

/**
 * Created by mei on 2014/9/30.
 */
public class ImageUtil {
    /**
     * 放大缩小图片
     */
    public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
        Bitmap newbmp = null;
        if (bitmap != null) {
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            Matrix matrix = new Matrix();
            float scaleWidht = ((float) w / width);
            float scaleHeight = ((float) h / height);
            matrix.postScale(scaleWidht, scaleHeight);
            newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix,
                    true);
        }
        return newbmp;
    }

    /**
     * 放大缩小图片
     */
    public static Bitmap zoomBitmap(int imgId, int w, int h) {
        Bitmap bitmap = BitmapFactory.decodeResource(MainApp.getInstance().getResources(), imgId);
        return zoomBitmap(bitmap, w, h);
    }
}
